<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>待办事项</title>
    <% include ../../layouts/import.ejs %>

</head>
<body>
<!--头部-->
<% include ../../layouts/header.ejs %>
<!--..-->

<div class="container">
    <div class="row">
        <div class="daiban">
            <div id="calendar"></div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function() {

        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            //点击日期事件
            dayClick: function(date, allDay, jsEvent, view) {
                layer.open({
                    type: 2,
                    title: '添加任务',
                    maxmin: true,
                    shadeClose: true,
                    area: ['500px', '400px'],
                    content: '/daily/schedule/add',
                    btn: ['保存', '关闭'],
                    btn1: function (index, layero) {  //保存
                        var transactor = layer.getChildFrame("#transactor", index).val();
                        var task_status = layer.getChildFrame("#task_status", index).val();
                        var task_title = layer.getChildFrame("#task_title", index).val();
                        var task_description = layer.getChildFrame("#task_description", index).val();
                        var start_time = layer.getChildFrame("#start_time", index).val();
                        var end_time = layer.getChildFrame("#end_time", index).val();
                        $.post('/daily/schedule/save', {
                            transactor:transactor,
                            task_status:task_status,
                            task_title:task_title,
                            task_description:task_description,
                            start_time:start_time,
                            end_time:end_time,
                        },function (result) {
                            layer.close(index);
                            $('#calendar').fullCalendar('refetchEvents');
                        })
                    },
                    cancel: function () {

                    }

                });
            },
            //点击日期内的事件
            eventClick: function(calEvent, jsEvent, view) {
                var id=calEvent.id;
                layer.open({
                    type: 2,
                    title: '编辑内容',
                    maxmin: true,
                    shadeClose: true,
                    area: ['500px', '400px'],
                    content: '/daily/schedule/modify/' + id,
                    btn: ['保存','删除','关闭'],
                    //保存
                    btn1: function (index, layero) {
                        var id = layer.getChildFrame("#id", index).val();
                        var transactor = layer.getChildFrame("#transactor", index).val();
                        var task_status = layer.getChildFrame("#task_status", index).val();
                        var task_title = layer.getChildFrame("#task_title", index).val();
                        var task_description = layer.getChildFrame("#task_description", index).val();
                        var start_time = layer.getChildFrame("#start_time", index).val();
                        var end_time = layer.getChildFrame("#end_time", index).val();
                        $.post('/daily/schedule/save', {
                            id:id,
                            transactor:transactor,
                            task_status:task_status,
                            task_title:task_title,
                            task_description:task_description,
                            start_time:start_time,
                            end_time:end_time,
                        },function (result) {
                            layer.close(index);
                            $('#calendar').fullCalendar('refetchEvents');
                        })
                    },
                    //删除
                    btn2: function (index, layero) {
                        $.get('/daily/schedule/delete/' + id, {id: id}, function (result) {
                            $("#calendar").fullCalendar("removeEvents",[ id ]);
                            // location.reload()
                        });
                        console.log(id);
                    },
                    cancel: function () {

                    }
                });
            },
            firstDay:1,
            editable: false,
            timeFormat: 'H:mm',
            axisFormat: 'H:mm',
            events: '/daily/schedule/calendarData'
        });

    });
</script>

<!--底部-->
<% include ../../layouts/footer.ejs %>
<!--....-->
</body>
</html>